<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use cmf\controller\BaseController;

use think\Db;

	class MakeqrcodeController extends AdminBaseController
	{



		function make(){
			// echo session('super_role_id');
			// exit;
			$arr=array('user_id'=>session('ADMIN_ID'));
			 // echo session('ADMIN_ID');
			 // exit;
			$json=urlencode(json_encode($arr));
			//require '../simplewind/vendor/phpqrcode';
            require '../simplewind/vendor/phpqrcode/phpqrcode.php';
            $value="http://v2.crejoy.cn/api/login/wx_jsapi_login?sign=erp_bind&ext=$json";  
            $img_name=uniqid().'.png';
            $filename = '../public/upload/qrcode/'.$img_name; 
	        $errorCorrectionLevel = "L"; // 纠错级别：L、M、Q、H  
	        $matrixPointSize = "4"; // 点的大小：1到10  
            //return redirect($value);
           \QRcode::png($value,  $filename,  $errorCorrectionLevel, $matrixPointSize,2);

        
      //  echo 'SERVER_NAME：'.$_SERVER['SERVER_NAME'];
     //   exit;
         //  echo $filename;
           //echo $img_name;http://10.172.18.144/admin/Makeqrcode/make
           $img_url = 'http://'.$_SERVER['SERVER_NAME'] .'/upload/qrcode/'.$img_name;
        //   echo "<img src=http://10.172.18.144/upload/qrcode/";
          // echo $img_name;
          // echo " />";
           //echo $img_url;
            $this->assign('img_url',$img_url);
            return $this->fetch();
           // http://localhost/upload/qrcode/55555.png






		}



		function bind(){

			$back_info = $_REQUEST;
			//var_dump($back_info);
			// exit;
			$code=$back_info['code'];
			//$code = '011nQ18Q1qjUO71UXbaQ1Zxn8Q1nQ18v';
			$url = "http://v2.crejoy.cn/api/login/check_login_wx?code=$code&type=2";
			//echo $url;
			$info = sqcurl($url, 'get', array(), array());
			$arr = json_decode(json_encode(json_decode($info)),true);
			//var_dump($arr['data']);
			$data['id'] = $back_info['user_id'];
			$data['app_userid'] = $arr['data']['id'] ;
			$is_has = db('user')->where('id',$back_info['user_id'])->find();
			if($is_has['app_userid']){
				if($is_has['app_userid'] == $arr['data']['id']){
					echo 111111;
					return '111111已经绑定，无需重复绑定';
				}
				$data['wx_nickname'] = $arr['data']['user_nickname'];
				$update=db('user')->update($data);
				return '已经更绑';
			}
			$data['wx_nickname'] = $arr['data']['user_nickname'];
			$update=db('user')->update($data);
			if($update){
				return '绑定成功';
			}else{
				return '绑定失败';
			}
			//db('incubator')->
			// var_dump($arr);



		}






























	}
